package com.corp.common.base.wrapper;

import io.swagger.annotations.ApiModelProperty;

import javax.validation.constraints.Min;
import java.io.Serializable;

/**
 * Description: api分页请求对象
 * Copyright: Copyright (c) 2020
 *
 * @author yf
 * @date 2019/7/22
 */
public abstract class PageReq implements Serializable {
    private static final long serialVersionUID = 1504753927348250106L;

    public static final transient String DESC = "desc";
    public static final transient String ASC = "asc";

    // 当前页码
    @Min(value = 1, message = "请指定正确的开始页码")
    @ApiModelProperty(value = "页码", required = true, dataType = "Long", allowableValues = "range[1,100]")
    long pageNo = 1;

    // 每页显示条数
    @Min(value = 1, message = "请指定正确的最小分页大小")
    @ApiModelProperty(value = "每页显示条数", required = true, dataType = "Long", allowableValues = "range[1,1000]")
    long pageSize = 10;

    //排序字段
    @ApiModelProperty(value = "排序字段", notes = "多字段以,分割")
    String sidx;

    //排序方式
    @ApiModelProperty(value = "排序方式", notes = "asc or desc", allowableValues = "asc,desc")
    String order;

    //默认排序方式
    @ApiModelProperty(hidden = true)
    String asc;

    public long getPageNo() {
        return pageNo;
    }

    public void setPageNo(long pageNo) {
        this.pageNo = pageNo;
    }

    public long getPageSize() {
        return pageSize;
    }

    public void setPageSize(long pageSize) {
        this.pageSize = pageSize;
    }

    public String getSidx() {
        return sidx;
    }

    public void setSidx(String sidx) {
        this.sidx = sidx;
    }

    public String getOrder() {
        return order;
    }

    public void setOrder(String order) {
        this.order = order;
    }

    public String getAsc() {
        return asc;
    }

    public void setAsc(String asc) {
        this.asc = asc;
    }

    @ApiModelProperty(hidden = true)
    public long getOffset() {
        return (pageNo - 1) * pageSize;
    }


}
